package com.saicmotor.workmanager;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

/**
 * @Author xinxinzhang
 * @Date 2022/08/18
 **/
public class ProgressWorker extends Worker {

    public ProgressWorker(
            @NonNull Context context,
            @NonNull WorkerParameters parameters) {
        super(context, parameters);
        // 初始进度0
        setProgressAsync(new Data.Builder().putInt("PROGRESS", 0).build());
    }

    @NonNull
    @Override
    public Result doWork() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException exception) {
        }
        setProgressAsync(new Data.Builder().putInt("PROGRESS", 100).build());
        return Result.success();
    }
}
